//
//  tuWenXiangQingViewController.m
//  YuErmuYing
//
//  Created by Tiancheng on 16/9/9.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "tuWenXiangQingViewController.h"
#import "yiYuanDuoBaoNextView.h"
#import "goodsDetailViewController.h"
#import "HttpRequest.h"
#import "goodsDetail.h"
#import "Macros.h"
#import "UIImageView+WebCache.h"

@interface tuWenXiangQingViewController ()
@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (weak, nonatomic) IBOutlet UIView *headerView01;
@property (weak, nonatomic) IBOutlet UIScrollView *backGroundScrollView;
@property (weak, nonatomic) IBOutlet UIView *backGroundView;

@property(nonatomic,copy)NSMutableArray *dataArray;


@end

@implementation tuWenXiangQingViewController
@synthesize dataArray;
- (void)viewDidLoad
{
    [super viewDidLoad];
    dataArray=[NSMutableArray array];

    [self setBackGroundColor];
    [self getDataFromNet];
}
//设置背景色
-(void)setBackGroundColor
{
self.headerView.backgroundColor=[UIColor colorWithRed:244/255.0 green:142/255.0 blue:177/255.0 alpha:1];
self.headerView01.backgroundColor=[UIColor colorWithRed:240/255.0 green:98/255.0 blue:146/255.0 alpha:1];

}
//从服务器获取数据
-(void)getDataFromNet
{
    goodsDetail *gd=[goodsDetail shardeManager];
    NSString*urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/indiana/picture"];
    NSMutableDictionary *parameters=[NSMutableDictionary dictionary];
    parameters[@"id"]=gd.idString;
    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlString parameters:parameters success:^(id responseObject)
     {
         id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         dataArray=[json objectForKey:@"data"];
         if (dataArray.count>0)
         {
             [self setImage];
         }
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];
}
-(void)setImage
{
    int num=(int)dataArray.count;
    for (int i=0; i<num; i++)
    {
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0.5786*screenWidth*i, screenWidth, 0.5786*screenWidth)];
        NSString *picString=dataArray[i];
        //图像
        NSURL* imagePath = [NSURL URLWithString:picString];
        [imageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
        [self.backGroundView addSubview:imageView];
        
    }
        float height=0.5786*screenWidth*num+5;
        CGSize size=CGSizeMake(0,height);
        self.backGroundScrollView.contentSize=size;

}
- (IBAction)goBack:(id)sender
{
    //跳到指定的界面
    for (UIViewController *controller in self.navigationController.viewControllers)
    {
        if ([controller isKindOfClass:[goodsDetailViewController class]])
        {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }

//    yiYuanDuoBaoNextView *yydb=[yiYuanDuoBaoNextView shardeManager];
//    if (yydb.whichViewToNext==1)
//    {
//        goodsDetailViewController *gdvc=self.navigationController.viewControllers[2];
//        [self.navigationController popToViewController:gdvc animated:YES];
//    }
//    if (yydb.whichViewToNext==3)
//    {
//        //跳到指定的界面
//        for (UIViewController *controller in self.navigationController.viewControllers)
//        {
//            if ([controller isKindOfClass:[goodsDetailViewController class]])
//            {
//                [self.navigationController popToViewController:controller animated:YES];
//            }
//        }
//    }
//    if (yydb.whichViewToNext==4)
//    {
//        //跳到指定的界面
//        for (UIViewController *controller in self.navigationController.viewControllers)
//        {
//            if ([controller isKindOfClass:[goodsDetailViewController class]])
//            {
//                [self.navigationController popToViewController:controller animated:YES];
//            }
//        }
//    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
